//
//  LGFollowDataSyptomCell.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/6/21.
//

#import "LGFollowDataPressureCell.h"

#define baseWidth     (Screen_W-viewPix(56))
#define dateWidth     (65/320.0)*baseWidth
#define itemWidth     (68/320.0)*baseWidth

@interface LGFollowDataPressureCell()
/**   */
@property (nonatomic , strong)UIView *shadowView;
/**   */
@property (nonatomic , strong)UIView *baseView;
/**   */
@property (nonatomic , strong)UIView *topLineView;
/**   */
@property (nonatomic , strong)UIView *lineView1;
/**   */
@property (nonatomic , strong)UIView *lineView2;
/**   */
@property (nonatomic , strong)UIView *lineView3;
/**   */
@property (nonatomic , strong)UIView *lineView4;
/**   */
@property (nonatomic , strong)UILabel *dateLabel;
/**   */
@property (nonatomic , strong)UIButton *highBtn;
/**   */
@property (nonatomic , strong)UIButton *lowBtn;
/**   */
@property (nonatomic , strong)UIButton *heartBtn;
/**   */
@property (nonatomic , strong)UIButton *checkButton;
@end

@implementation LGFollowDataPressureCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubView];
    }
    return  self;
}

-(void)setShowCorner:(BOOL)showCorner{
    _showCorner = showCorner;
    CGFloat bottom = (showCorner == YES)?-viewPix(10):0;
    [self.baseView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.shadowView).offset(bottom);
    }];
}

-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    NSDictionary *iconDic = @{@"high":@"监测-偏高",@"low":@"监测-偏低"};
    NSDictionary *colorDic = @{@"high":@"#DB453A",@"low":@"#3291FF"};
    self.dateLabel.text = LGNSString(dataDic[@"record_time"]);
    
    [self.highBtn setTitle:LGNSString(dataDic[@"sbp"]) forState:UIControlStateNormal];
    [self.lowBtn setTitle:LGNSString(dataDic[@"dbp"]) forState:UIControlStateNormal];
    [self.heartBtn setTitle:LGNSString(dataDic[@"hr"]) forState:UIControlStateNormal];
    NSString *hightName = [dataDic[@"sbp_ab"] length]>0?iconDic[dataDic[@"sbp_ab"]]:@"";
    NSString *lowName = [dataDic[@"dbp_ab"] length]>0?iconDic[dataDic[@"dbp_ab"]]:@"";
    NSString *heartName = [dataDic[@"hr_ab"] length]>0?iconDic[dataDic[@"hr_ab"]]:@"";
    [self.highBtn setImage:[UIImage imageNamed:hightName] forState:UIControlStateNormal];
    [self.lowBtn setImage:[UIImage imageNamed:lowName] forState:UIControlStateNormal];
    [self.heartBtn setImage:[UIImage imageNamed:heartName] forState:UIControlStateNormal];
    NSString *hightColor = [dataDic[@"sbp_ab"] length]>0?colorDic[dataDic[@"sbp_ab"]]:@"#333333";
    NSString *lowColor = [dataDic[@"dbp_ab"] length]>0?colorDic[dataDic[@"dbp_ab"]]:@"#333333";
    NSString *heartColor = [dataDic[@"hr_ab"] length]>0?colorDic[dataDic[@"hr_ab"]]:@"#333333";
    [self.highBtn setTitleColor:[UIColor colorWithString:hightColor] forState:UIControlStateNormal];
    [self.lowBtn setTitleColor:[UIColor colorWithString:lowColor] forState:UIControlStateNormal];
    [self.heartBtn setTitleColor:[UIColor colorWithString:heartColor] forState:UIControlStateNormal];
    
    if([dataDic[@"sbp_ab"] length]){
        [self.highBtn setButtonInsetsStyle:LGButtonInsetsStyleRight marginSpace:2];
    }else{
        [self.highBtn setButtonInsetsStyle:LGButtonInsetsStyleLeft marginSpace:0];
    }
    
    if([dataDic[@"dbp_ab"] length]>0){
        [self.lowBtn setButtonInsetsStyle:LGButtonInsetsStyleRight marginSpace:2];
    }else{
        [self.lowBtn setButtonInsetsStyle:LGButtonInsetsStyleLeft marginSpace:0];
    }
    
    if([dataDic[@"hr_ab"] length]>0){
        [self.heartBtn setButtonInsetsStyle:LGButtonInsetsStyleRight marginSpace:2];
    }else{
        [self.heartBtn setButtonInsetsStyle:LGButtonInsetsStyleLeft marginSpace:0];
    }
   
    if([dataDic[@"ecg_id"] integerValue]>0){
        [self.checkButton setTitleColor:[UIColor colorWithString:@"#3291FF"] forState:UIControlStateNormal];
        [self.checkButton setTitle:@"查看" forState:UIControlStateNormal];
        self.checkButton.userInteractionEnabled = YES;
    }else{
        [self.checkButton setTitleColor:[UIColor colorWithString:@"#333333"] forState:UIControlStateNormal];
        [self.checkButton setTitle:@"--" forState:UIControlStateNormal];
        self.checkButton.userInteractionEnabled = NO;
    }
}

//查看心电图
-(void)checkChartAction:(UIButton *)sender{
    if(self.delegate && [self.delegate respondsToSelector:@selector(checkHeartReport:)]){
        [self.delegate checkHeartReport:self.dataDic];
    }
}

#pragma mark
#pragma mark ====> 创建控件
-(void)createSubView{
    self.clipsToBounds = YES;
    self.backgroundColor = [UIColor colorWithString:@"#F9F9F9"];
    [self.contentView addSubview:self.shadowView];
    [self.shadowView addSubview:self.baseView];
    [self.shadowView addSubview:self.topLineView];
    [self.baseView addSubview:self.dateLabel];
    [self.baseView addSubview:self.highBtn];
    [self.baseView addSubview:self.lowBtn];
    [self.baseView addSubview:self.heartBtn];
    [self.baseView addSubview:self.checkButton];
    [self.baseView addSubview:self.lineView1];
    [self.baseView addSubview:self.lineView2];
    [self.baseView addSubview:self.lineView3];
    [self.baseView addSubview:self.lineView4];
    [self.shadowView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(-viewPix(5));
        make.left.equalTo(self.contentView).offset(viewPix(16));
        make.right.equalTo(self.contentView).offset(-viewPix(16));
        make.bottom.equalTo(self.contentView).offset(viewPix(5));
    }];
    [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.shadowView).offset(viewPix(12));
        make.right.equalTo(self.shadowView).offset(-viewPix(12));
        make.top.equalTo(self.shadowView);
        make.bottom.equalTo(self.shadowView).offset(0);
        make.height.equalTo(@(viewPix(40)));
    }];
    [self.topLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.baseView);
        make.top.equalTo(self.contentView);
        make.height.equalTo(@(0.5));
    }];
    [self.dateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.left.equalTo(self.baseView);
        make.width.equalTo(@(dateWidth));
    }];
    [self.highBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.dateLabel);
        make.left.equalTo(self.dateLabel.mas_right);
        make.width.equalTo(@(itemWidth));
    }];
    [self.lowBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.dateLabel);
        make.left.equalTo(self.highBtn.mas_right);
        make.width.equalTo(@(itemWidth));
    }];
    [self.heartBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.dateLabel);
        make.left.equalTo(self.lowBtn.mas_right);
        make.width.equalTo(@(itemWidth));
    }];
    [self.checkButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self.baseView);
        make.left.equalTo(self.heartBtn.mas_right);
        make.right.equalTo(self.baseView);
    }];
    [self.lineView1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self.baseView);
        make.left.equalTo(self.dateLabel.mas_right);
        make.width.equalTo(@(0.5));
    }];
    [self.lineView2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self.baseView);
        make.left.equalTo(self.highBtn.mas_right);
        make.width.equalTo(@(0.5));
    }];
    [self.lineView3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self.baseView);
        make.left.equalTo(self.lowBtn.mas_right);
        make.width.equalTo(@(0.5));
    }];
    [self.lineView4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self.baseView);
        make.left.equalTo(self.heartBtn.mas_right);
        make.width.equalTo(@(0.5));
    }];
}
-(UIView *)shadowView{
    if(!_shadowView){
        _shadowView = [UIView shadowViewWithColor:@"#B3C5D9" offset:CGSizeMake(0, 2) opacity:0.15 radius:10];
        _shadowView.backgroundColor = [UIColor whiteColor];
    }
    return _shadowView;
}

-(UIView *)baseView{
    if(!_baseView){
        _baseView = [[UIView alloc] init];
        _baseView.layer.borderColor = [UIColor colorWithString:@"#E0E0E0"].CGColor;
        _baseView.layer.borderWidth = 1;
        _baseView.cornerRidus = 7;
    }
    return _baseView;
}

-(UIView *)topLineView{
    if(!_topLineView){
        _topLineView = [[UIView alloc] init];
        _topLineView.backgroundColor = [UIColor colorWithString:@"#E0E0E0"];
    }
    return _topLineView;
}

-(UIView *)lineView1{
    if(!_lineView1){
        _lineView1 = [[UIView alloc] init];
        _lineView1.backgroundColor = [UIColor colorWithString:@"#E0E0E0"];
    }
    return _lineView1;
}

-(UIView *)lineView2{
    if(!_lineView2){
        _lineView2 = [[UIView alloc] init];
        _lineView2.backgroundColor = [UIColor colorWithString:@"#E0E0E0"];
    }
    return _lineView2;
}

-(UIView *)lineView3{
    if(!_lineView3){
        _lineView3 = [[UIView alloc] init];
        _lineView3.backgroundColor = [UIColor colorWithString:@"#E0E0E0"];
    }
    return _lineView3;
}

-(UIView *)lineView4{
    if(!_lineView4){
        _lineView4 = [[UIView alloc] init];
        _lineView4.backgroundColor = [UIColor colorWithString:@"#E0E0E0"];
    }
    return _lineView4;
}

-(UILabel *)dateLabel{
    if(!_dateLabel){
        _dateLabel = [UILabel lableWithText:@"日期" colorString:@"#666666" textFont:LGFont(12) textAlignment:NSTextAlignmentCenter lines:1];
    }
    return _dateLabel;
}

-(UIButton *)highBtn{
    if(!_highBtn){
        _highBtn = [UIButton buttonWithTitle:@"" titleFont:LGFont(16) textColor:@"#333333" imageName:@""];
        _highBtn.userInteractionEnabled = NO;
    }
    return _highBtn;
}

-(UIButton *)lowBtn{
    if(!_lowBtn){
        _lowBtn = [UIButton buttonWithTitle:@"" titleFont:LGFont(16) textColor:@"#333333" imageName:@""];
        _lowBtn.userInteractionEnabled = NO;
    }
    return _lowBtn;
}


-(UIButton *)heartBtn{
    if(!_heartBtn){
        _heartBtn = [UIButton buttonWithTitle:@"" titleFont:LGFont(16) textColor:@"#333333" imageName:@""];
        _heartBtn.userInteractionEnabled = NO;
    }
    return _heartBtn;
}

-(UIButton *)checkButton{
    if(!_checkButton){
        _checkButton = [UIButton buttonWithTitle:@"-" titleFont:LGFont(14) normalColor:@"#333333" selectColor:@"#3291FF"];
        [_checkButton setTitle:@"查看" forState:UIControlStateSelected];
        [_checkButton addTarget:self action:@selector(checkChartAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _checkButton;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
